using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Service.Interfaces;
using Widgetsphere.Core.DataAccess;
using ACME.Northwind.DALProxy.Extensions;

namespace ACME.Northwind.DALProxy
{
	/// <summary>
	/// The service implementation for CustomerCustomerDemo object
	/// </summary>
	public partial class CustomerCustomerDemoService : ICustomerCustomerDemoService
	{
		#region ICustomerCustomerDemoService Members

		/// <summary>
		/// Run a selection by the primary key
		/// </summary>
		public CustomerCustomerDemoDTO SelectByPrimaryKey(string customerid, string customertypeid)
		{
			CustomerCustomerDemoDTO retVal = new CustomerCustomerDemoDTO();
			if (!retVal.SelectUsingPK(customerid, customertypeid)) return null;
			else return retVal;
		}

		/// <summary>
		/// Run the persist for an object
		/// </summary>
		public bool Persist(CustomerCustomerDemoDTO dto)
		{
			return (dto.Persist() != null);
		}

		/// <summary>
		/// Run the persist for a list
		/// </summary>
		public bool Persist(List<CustomerCustomerDemoDTO> list)
		{
			return list.Persist();
		}

		/// <summary>
		/// Run a selection for all objects
		/// </summary>
		public List<CustomerCustomerDemoDTO> RunSelect()
		{
			List<CustomerCustomerDemoDTO> retVal = new List<CustomerCustomerDemoDTO>();
			retVal.RunSelect();
			return retVal;
		}

		/// <summary>
		/// Run a selection using LINQ
		/// </summary>
		public List<CustomerCustomerDemoDTO> RunSelect(string linq)
		{
			List<CustomerCustomerDemoDTO> retVal = new List<CustomerCustomerDemoDTO>();
			retVal.RunSelect(linq);
			return retVal;
		}

		/// <summary>
		/// Run a paginated selection using LINQ
		/// </summary>
		public PagedQueryResults<CustomerCustomerDemoDTO> RunSelect(int pageIndex, int pageSize, bool ascending, string sortColumn, string linq)
		{
			List<CustomerCustomerDemoDTO> list = new List<CustomerCustomerDemoDTO>();
			string sortOrder;
			if (ascending)
				sortOrder = "ascending";
			else
				sortOrder = "descending";
			return list.RunSelect(pageSize.ToString(), pageIndex.ToString(), sortOrder, sortColumn, linq);
		}

		/// <summary>
		/// Return the related CustomerDemographic item
		/// </summary>
		public CustomerDemographicDTO GetCustomerDemographicItem(CustomerCustomerDemoDTO item)
		{
			CustomerDemographicDTO retval = new CustomerDemographicDTO();
			retval.SelectUsingPK(item.CustomerTypeId);
			return retval;
		}

		/// <summary>
		/// Return the related Customer item
		/// </summary>
		public CustomerDTO GetCustomerItem(CustomerCustomerDemoDTO item)
		{
			CustomerDTO retval = new CustomerDTO();
			retval.SelectUsingPK(item.CustomerId);
			return retval;
		}

		/// <summary>
		/// Delete the specified item
		/// </summary>
		public bool Delete(CustomerCustomerDemoDTO item)
		{
			CustomerCustomerDemo customercustomerdemo = CustomerCustomerDemo.SelectUsingPK(item.CustomerId, item.CustomerTypeId);
			if (customercustomerdemo == null) return false;
			customercustomerdemo.Delete();
			customercustomerdemo.Persist();
			return true;
		}

		#endregion

	}
}
